<template>
  <div class="photoinfo-container">
    <h3>{{imageInfo.title}}</h3>
    <div class="sub-tit">
      <span>{{imageInfo.add_time | dateformat}}</span>
      <span>{{imageInfo.click}}</span>
    </div>
    <!-- 缩略图 -->
    <div>
      <vue-preview
        :list="thumimages"
        :thumbImageStyle="{width: '80px', height: '80px', margin: '10px'}"
        :previewBoxStyle="{border: '1px solid #eee'}"
        :tapToClose="true"
        @close="closeHandler"
        @destroy="destroyHandler"
      />
    </div>
    <div class="content" v-html="imageInfo.content"></div>
    <cmt-box :artid="id"></cmt-box>
  </div>
</template>

<script>
import comment from "../subcomponents/comments.vue";
export default {
  data() {
    return {
      imageInfo: {},
      id: this.$route.params.id,
      thumimages: []
    };
  },
  created() {
    this.getimageInfo();
    this.getthumimages();
  },
  methods: {
    getimageInfo() {
      this.$http.get("api/getimageInfo/" + this.id).then(result => {
        if (result.body.status == 0) {
          this.imageInfo = result.body.message[0];
        } else {
          Toast("加载失败");
        }
      });
    },
    getthumimages() {
      // 获取缩略图
      this.$http.get("api/getthumimages/" + this.id).then(result => {
        if (result.body.status === 0) {
          // 循环每个图片数据，补全图片的宽和高
          result.body.message.forEach(item => {
            item.w = 600;
            item.h = 400;
          });
          // 把完整的数据保存到 thumimages 中
          this.thumimages = result.body.message;
        }
      });
    },
    handleClose() {
      console.log("close event");
    }
  },
  components: {
    // 注册 评论子组件
    "cmt-box": comment
  }
};
</script>

<style lang="scss" scope>
.photoinfo-container {
  padding-bottom: 50px;
  h3 {
    color: #26a2ff;
    font-size: 14px;
    line-height: 30px;
    text-align: center;
  }
  .sub-tit {
    display: flex;
    justify-content: space-around;
    font-size: 12px;
    padding-bottom: 10px;
    border-bottom: 1px solid #ccc;
  }
  img {
    margin: 10px;
    box-shadow: 0 0 8px #999;
  }
  .content {
    font-size: 12px;
    line-height: 20px;
    padding: 10px;
    color: #333;
  }
}
</style>